﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using CustomsSystem.BLL;
using CustomsSystem.Model;
using System.Collections.Generic;
using Maticsoft.Common;

namespace WEB.Client
{
    public partial class sheetDetails : System.Web.UI.Page
    {
        DataSet ds;
        SheetInfoManage bll = new SheetInfoManage();
        int flowstartid;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)   
                {
                #region 委托单信息载入
                    int id = Convert.ToInt32(Request.QueryString["ID"]);
                    //委托单号显示
                    lbsheet.Visible = true;
                    lbSheetValue1.Text = id.ToString();
                    lbSheetValue1.Visible = true;
                    ///*载入数据*/
                    CustomsSystem.Model.sheetInfo mySheetInfo = new CustomsSystem.Model.sheetInfo();//定义model
                    mySheetInfo = bll.GetModel(id);//查询数据
                    //业务类别
                    if (mySheetInfo.typeID == 1)
                    {
                        lbTypeId.Text = "报关";
                    }
                    else if (mySheetInfo.typeID == 2)
                    {
                        lbTypeId.Text = "报检";
                    }
                    else if (mySheetInfo.typeID == 4)
                    {
                        lbTypeId.Text = "报关报检";
                    }
                    else if (mySheetInfo.typeID == 5)
                    {
                        lbTypeId.Text = "加签";
                    }
                    else if (mySheetInfo.typeID == 6)
                    {
                        lbTypeId.Text = "危险品";
                    }
                    else if (mySheetInfo.typeID == 6)
                    {
                        lbTypeId.Text = "其他";
                    }
                    //查询代码表
                    CodeManage codeBll1 = new CodeManage();
                    Info_code codeModel1 = codeBll1.GetModel("inoutType", mySheetInfo.inOut);
                    lbInOut1.Text=codeModel1.codeName.ToString();
                    //工作流模板
                    WorkflowManage workBll = new WorkflowManage();
                    if (Convert .ToInt32( mySheetInfo.InfoWKTypeIDbg.ToString()) >0)
                    {
                        List<CustomsSystem.Model.Info_workflowMaster> worklist = workBll.GetModelListMaster("InfoWKTypeID ='" + mySheetInfo.InfoWKTypeIDbg+"'");
                        if (worklist.Count!=0)
                        {
                            lbworkflowInfo1.Text = worklist[0].WKTypeName.ToString();
                        }
                    }

                    if (Convert .ToInt32(mySheetInfo.InfoWKTypeIDbj.ToString() )>0)
                    {
                        List<CustomsSystem.Model.Info_workflowMaster> worklist2 = workBll.GetModelListMaster("InfoWKTypeID ='" + mySheetInfo.InfoWKTypeIDbj+"'");
                        if (worklist2.Count!=0)
                        {
                            lbworkflowInfo2.Text = worklist2[0].WKTypeName.ToString();
                        }
                    }

                    //根据公司ID获取公司名字
                    CustomerManage cusBll = new CustomerManage();
                    Customer cusModel = cusBll.GetModel(mySheetInfo.cID);
                    string cusomerName = cusModel.CustomerName;
                    lbCid1.Text = cusomerName;
                    //根据货物ID取名字
                    CodeManage codeBll = new CodeManage();
                    Info_code codeModel = codeBll.GetModel("goodType", mySheetInfo.goodsType);
                   string goodsType="";
                   if (codeModel != null)
                    {
                        goodsType = codeModel.codeName.ToString();
                    }

                    lbGoodsType1.Text = goodsType;
                    lbGency1.Text = mySheetInfo.agencyDate.ToString();
                    lbShipName1.Text = mySheetInfo.shipName;
                    lbGoodsName1.Text = mySheetInfo.goodsName;
                    lbNO.Text=mySheetInfo .No;
                    lbCustomsNo11.Text = mySheetInfo.customsNo;
                    lbInspectionNo1.Text = mySheetInfo.inspectionNo;
                    lbContractNo1.Text = mySheetInfo.contractNo;
                    lbAgency1.Text = mySheetInfo.agency;
                    lbshipCompany1.Text = mySheetInfo.shipCompany;
                    lbRemark1.Text = mySheetInfo.remark;
                    codeModel = codeBll.GetModel("tradeType", Convert.ToInt32(mySheetInfo.tradeType.ToString()));
                    lbtradeType.Text = codeModel.codeName;
                    lbBatchNO.Text=mySheetInfo.BatchNO.ToString();
                    lbTestItem.Text=mySheetInfo.TestItem.ToString ();
                    lbModel.Text=mySheetInfo.Model.ToString();
                    lbRegUnit.Text=mySheetInfo.RegisterUnit.ToString();
                    ckDG.Checked=mySheetInfo.DangerousGoods;
                    lbTransport.Text=mySheetInfo.Transport.ToString();
                    lbLadingBillNo1.Text = mySheetInfo.ladingBillNo;
                    lbContainerNo1.Text = mySheetInfo.containerNo;
                    lbHeadBillNo1.Text = mySheetInfo.headLadingBillNo;
                    lbTransferNo11.Text = mySheetInfo.transferNo1;
                    lbTransferNo12.Text = mySheetInfo.transferNo2;
                    lbTransferNo13.Text = mySheetInfo.transferNo3;
                    lbFilingNo1.Text = mySheetInfo.filingNo;
                    lbInvTitle1.Text = mySheetInfo.invTilte;
                    lbInspection1.Text = mySheetInfo.inspetionAgancy;
                    lbPO.Text=mySheetInfo.PO.ToString();
                    //录入员
                    UserManage user = new UserManage();
                    if (mySheetInfo.inputEmpNo != "")
                    {
                        lbInputEmpNo1.Text = user.GetList(" where EMPNum = '" + mySheetInfo.inputEmpNo+"'").Tables[0].Rows[0]["UserName"].ToString();
                    }
                    else
                    {
                        lbInputEmpNo1.Text = "";
                    }

                    lbInputDate1.Text = mySheetInfo.inputDate.ToString();
                    #endregion
                }
                else if (Request.QueryString["plan"] !=null)
                {
                #region 业务计划
                    int id = Convert.ToInt32(Request.QueryString["plan"]);
                    //委托单号显示
                    lbsheet.Text = "单号";
                    lbsheet.Visible = true;
                    lbSheetValue1.Text = id.ToString();
                    lbSheetValue1.Visible = true;
                    ///*载入数据*/
                    CustomsSystem.Model.T_plan mySheetInfo = new CustomsSystem.Model.T_plan();
                    planManage plan = new planManage();
                    mySheetInfo = plan.GetModel(id);
                    //业务类别
                    if (mySheetInfo.typeID == 1)
                    {
                        lbTypeId.Text = "报关";
                    }
                    else if (mySheetInfo.typeID == 2)
                    {
                        lbTypeId.Text = "报检";
                    }
                    else if (mySheetInfo.typeID == 4)
                    {
                        lbTypeId.Text = "报关报检";
                    }
                    else if (mySheetInfo.typeID == 5)
                    {
                        lbTypeId.Text = "加签";
                    }
                    else if (mySheetInfo.typeID == 6)
                    {
                        lbTypeId.Text = "危险品";
                    }
                    else if (mySheetInfo.typeID == 6)
                    {
                        lbTypeId.Text = "其他";
                    }
                    //查找代码表
                    CodeManage codeBll1 = new CodeManage();
                    Info_code codeModel1 = codeBll1.GetModel("inoutType",Convert.ToInt32(mySheetInfo.inOut));
                    lbInOut1.Text = codeModel1.codeName.ToString();
                    //工作流模板
                    WorkflowManage workBll = new WorkflowManage();
                    if (mySheetInfo.InfoWKTypeIDbg.ToString() != "")
                    {
                        List<CustomsSystem.Model.Info_workflowMaster> worklist = workBll.GetModelListMaster("InfoWKTypeID ='" + mySheetInfo.InfoWKTypeIDbg+"'");
                        if (worklist.Count != 0)
                        {
                            lbworkflowInfo1.Text = worklist[0].WKTypeName.ToString();
                        }
                    }

                    if (mySheetInfo.InfoWKTypeIDbj.ToString() != "-1")
                    {
                        List<CustomsSystem.Model.Info_workflowMaster> worklist2 = workBll.GetModelListMaster("InfoWKTypeID ='" + mySheetInfo.InfoWKTypeIDbj+"'");
                        if (worklist2.Count != 0)
                        {
                            lbworkflowInfo1.Text = worklist2[0].WKTypeName.ToString();
                        }
                    }

                    //根据公司ID获取公司名字
                    CustomerManage cusBll = new CustomerManage();
                    Customer cusModel = cusBll.GetModel(mySheetInfo.cID);
                    string cusomerName = cusModel.CustomerName;
                    lbCid1.Text = cusomerName;
                    //根据货物ID取名字
                    CodeManage codeBll = new CodeManage();
                    Info_code codeModel = codeBll.GetModel("goodType",int.Parse(mySheetInfo.goodsType.ToString()));
                    string goodsType = "";
                    if (codeModel != null )
                    {
                        goodsType = codeModel.codeName.ToString();
                    }

                    lbGency1.Text = mySheetInfo.agencyDate.ToString();
                    lbShipName1.Text = mySheetInfo.shipName;
                    lbGoodsName1.Text = mySheetInfo.goodsName;
                    lbNO.Text=mySheetInfo.No.ToString();
                    lbCustomsNo11.Text = mySheetInfo.customsNo;
                    lbInspectionNo1.Text = mySheetInfo.inspectionNo;
                    lbContractNo1.Text = mySheetInfo.contractNo;
                    lbAgency1.Text = mySheetInfo.agency;
                    lbshipCompany1.Text = mySheetInfo.shipCompany;
                    lbRemark1.Text = mySheetInfo.remark;
                    lbLadingBillNo1.Text = mySheetInfo.ladingBillNo;
                    lbContainerNo1.Text = mySheetInfo.containerNo;
                    lbHeadBillNo1.Text = mySheetInfo.headLadingBillNo;
                    lbTransferNo11.Text = mySheetInfo.transferNo1;
                    lbTransferNo12.Text = mySheetInfo.transferNo2;
                    lbTransferNo13.Text = mySheetInfo.transferNo3;
                    lbFilingNo1.Text = mySheetInfo.filingNo;
                    lbInvTitle1.Text = mySheetInfo.invTilte;
                    lbInspection1.Text = mySheetInfo.inspetionAgancy;
                    lbPO.Text = mySheetInfo.PO.ToString();
                    codeModel=codeBll.GetModel("tradeType",Convert.ToInt32(mySheetInfo.tradeType.ToString()));
                    lbtradeType.Text = codeModel.codeName;
                    lbBatchNO.Text = mySheetInfo.BatchNO.ToString();
                    lbTestItem.Text = mySheetInfo.TestItem.ToString();
                    lbModel.Text = mySheetInfo.Model.ToString();
                    lbRegUnit.Text = mySheetInfo.RegisterUnit.ToString();
                    ckDG.Checked = mySheetInfo.DangerousGoods;
                    lbTransport.Text = mySheetInfo.Transport.ToString();
                    //录入员
                    UserManage user=new UserManage();
                    if (mySheetInfo.inputEmpNo.Trim() != "")
                    {
                        lbInputEmpNo1.Text = user.GetList(" where EMPNum = '" + mySheetInfo.inputEmpNo+"'").Tables[0].Rows[0]["UserName"].ToString();
                    }
                    else
                    {
                        lbInputEmpNo1.Text = ""; 
                    }

                    lbInputDate1.Text = mySheetInfo.inputDate.ToString();

                    #endregion
                }
            }
        }
        /// <summary>
        /// 获取所有工作流模板
        /// </summary>
        /// <param name="ddl"></param>
        private void BindFlowInfo(DropDownList ddl)
        {
            WorkflowManage wfBll = new WorkflowManage();
            List<Info_workflowMaster> wfModels = wfBll.GetModelListMaster("");
            //获取数据
            foreach (Info_workflowMaster aflow in wfModels)
            {
                ddl.Items.Add(new ListItem(aflow.WKTypeName, aflow.infoWKTypeID.ToString()));
            }
        }

        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static string[] GetCustomersName(string prefixText, int count)
        {
            CustomerManage cusManage = new CustomerManage();
            List<string> strArray = new List<string>();
            //string[] strArray = { "中国石油公司","中顺洁柔","中山技术",
            //"捷达捷达捷达达","时代复分","幅度为爱"};
            List<Customer> cusList = cusManage.GetModelList("");
            foreach (Customer aCus in cusList)
            {
                strArray.Add(aCus.CustomerName);
            }
            return (from m in strArray
                    where m.Contains(prefixText)
                    select m).Take(count).ToArray();
        }
    }
}